package com.game.screen.physics;

import com.game.GameJam;
import com.game.screen.GameScreen;
import com.game.screen.Player;

public class HorizontalPlayerPhysics extends PlayerPhysics {

	private int maxY = 200;
	private int maxX = 250;
	private float windIter = 0.0f;
	private float windForce = 0.5f;
	protected float riseSpeed = 1;

	private boolean isRising = true;

	public void update(Player player) {

		windIter += 0.05f;

		if (player.asleep) {

			if (player.nextBub != null) {
				player.bubbles.get(player.numBubbles - 1).setImage(
						player.nextBub);
				player.nextBub = null;
			}

			float newX = pApplet.lerp(pApplet.mouseX, player.position.getX(), 0.99f);

			if (newX < maxX)
				player.position.setX(newX - (float) (Math.sin(windIter) * windForce));
			player.position.setY(player.position.getY()
					- (float) (Math.cos(windIter) * windForce));

			if (isRising) {
				player.position.setY(player.position.getY() - riseSpeed);
			} else {
				((GameScreen) ((GameJam) pApplet).currentScreen).bg.pause = false;
			}

			isRising = (player.position.getY() <= maxY) ? false : true;

			player.bubbles.get(0).update(player.position.getX() + 25,
					player.position.getY() + 35);

			for (int i = 1; i < player.numBubbles; i++) {
				player.bubbles.get(i).update(player.bubbles.get(i - 1).x,
						player.bubbles.get(i - 1).y);
			}

			player.boy.update(player.bubbles.get(player.numBubbles - 1).x - 20,
					player.bubbles.get(player.numBubbles - 1).y);
		}
	}
}
